package com.suian.spring.test;

import com.suian.spring.test.handler.DebugLogHandler;
import com.suian.spring.test.handler.ErrorLogHandler;
import com.suian.spring.test.handler.InfoLogHandler;

public class HandlerDemo {
    public static void main(String[] args) {
        InfoLogHandler infoLogHandler = new InfoLogHandler();
        DebugLogHandler debugLogHandler = new DebugLogHandler();
        ErrorLogHandler errorLogHandler = new ErrorLogHandler();

        infoLogHandler.setNext(errorLogHandler).setNext(debugLogHandler);

        // 模拟日志请求
        LogRequest request1 = new LogRequest(LogLevel.INFO, "用户登录成功");
        LogRequest request2 = new LogRequest(LogLevel.DEBUG, "查询参数: id=123");
        LogRequest request3 = new LogRequest(LogLevel.ERROR, "数据库连接失败");
        LogRequest request4 = new LogRequest(LogLevel.WARN, "内存使用率过高"); // 未定义处理器

        infoLogHandler.handleRequest(request1);
        infoLogHandler.handleRequest(request2);
        infoLogHandler.handleRequest(request3);
        infoLogHandler.handleRequest(request4);

    }
}
